<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/7/25
 * Time: 19:21
 */

namespace app\home\controller;


use think\Controller;
use think\Db;
use think\Request;

class Curriculum extends Controller{
    public function index(){//显示课程子页

        if($content = Db::table('course_classification')->select()){
            for ($aa=0;$aa<count($content);$aa++){
                $content[$aa]["class"]= Db::table('course_classification_fine')->field("id,record_name")->where("category_name="."'{$content[$aa]["name"]}'")->select();

            }
//                pre($content);
            return view("curriculum",["list"=>$content]);
        }else{
            echo '数据查询错误0';
        }

    }

    function ajaxurl(){
        if($content = Db::table('course_classification')->select()){
            for ($aa=0;$aa<count($content);$aa++){
                $content[$aa]["class"]= Db::table('course_classification_fine')->field("id,record_name")->where("category_name="."'{$content[$aa]["name"]}'")->select();
            }
        }
//        pre($content);
            echo json_encode($content);

    }
        public function course(){
            $course=Db::table("course")->where("category="."'{$_GET["category"]}'")->select();
            return view("course",["course"=>$course]);
        }
    public function curriculum(){   //课程点击分类 显示课程 查询方法
        if(Request::instance()->isGet()){
            if(isset($_GET['id'])){
                if($content = Db::table('course_classification')->select()){
                    if($contents = Db::table('course_classification_fine')->where('category_id',$_GET['id'])->select()){
                        if($contentss = Db::table('course')->select()){
                            return $this->fetch('curriculum',[
                                'list' => $content,
                                'last' => $contents,
                                'oth' => $contentss
                            ]);
                        }
                    }else{
                        echo '数据查询错误1';
                    }
                }else{
                    echo '数据查询错误2';
                }
            }elseif(isset($_GET['sid']) && isset($_GET['id'])){
                if($content = Db::table('course_classification')->select()){
                    if($contents = Db::table('course_classification_fine')->where('category_id',$_GET['id'])->select()){
                        if($contentss = Db::table('course')->where('id',$_GET['sid'])->select()){
                            return $this->fetch('curriculum',[
                                'list' => $content,
                                'last' => $contents,
                                'oth' => $contentss
                            ]);
                        }
                    }else{
                        echo '数据查询错误3';
                    }
                }else{
                    echo '数据查询错误4';
                }
            }elseif(isset($_GET['sid']) && isset($_GET['name'])){
                if($content = Db::table('course_classification')->select()){
                      if($con = Db::table('course_classification_fine')->where('id',$_GET['sid'])->find()){
                           if($contents = Db::table('course_classification_fine')->where('category_id',$con['category_id'])->select()) {
                                    $contentss = Db::table('course')->where('category', $_GET['name'])->select();
                                        return $this->fetch('curriculum', [
                                            'list' => $content,
                                            'last' => $contents,
                                            'oth' => $contentss,

                                        ]);
                           }
                      }else{
                           echo '数据查询错误5';
                           }
                }else{
                     echo '数据查询错误6';
                     }
            }
        }
    }
}